import 'package:flutter_tech_shop/src/shared/Product.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';

class CartController extends GetxController {
  final products = <Product>[].obs;
  final favorites = <Product>[].obs;

  addProduct(Product newProduct) {
    if (products.contains(newProduct)) {
      products[products.indexOf(newProduct)].count++;
    } else {
      products.add(newProduct);
    }
    Fluttertoast.showToast(msg: '添加成功');
  }

  addFavorite(Product newFavorite) {
    if (!favorites.contains(newFavorite)) {
      favorites.add(newFavorite);
    }
  }

  removeFavorite(Product product) {
    if (favorites.contains(product)) {
      favorites.remove(product);
    }
  }
}
